package leetcode_600;

import java.util.HashMap;
import java.util.Map;

/**
 *@author 周杨  
 *EncodeAndDecodeTinyURL_535 对一个url进行加码解码
 *describe:计算当前的count 然后算出唯一的16进制编码 AC 50%
 *2018年9月11日 下午12:31:23
 */
public class EncodeAndDecodeTinyURL_535 {
	  private long count = 0;
	    private Map<String, String> table = new HashMap<String, String>();
	    
	    // Encodes a URL to a shortened URL.
	    public String encode(String longUrl) {
	        String str = increase();
	        String shortUrl = "http://" + str;
	        table.put(shortUrl, longUrl);
	        return shortUrl;
	    }

	    // Decodes a shortened URL to its original URL.
	    public String decode(String shortUrl) {
	        return table.get(shortUrl);
	    }
	    
	    public String increase() {
	        return Long.toHexString(++count);
	    }
}
